# -*- coding: utf-8 -*-
"""
Created on Wed Mar 13 20:28:01 2013

The goal of this project is to use a simple fractal terrain generator to
create a fun game that I called car ride. The idea is of a lunar vehicle
controlled by the user, that has as objective to reach as far as possible
without crashing the vehicle.

So far I have the terrain generator working and some textures applied to the Scenery.

Using the right arrow key you can explore the world scene

@author: Henrique Arroyo
"""

import os, sys

import pygame
import pygame.gfxdraw
import random
import Scenery

from pygame.locals import *
import Object

if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'

class PyMain:
    
    def __init__(self, width, height):
        
        self.step = 20
        self.moving = False
        
        self.width = width
        self.height = height    
        
        pygame.init()
        
        self.surface = pygame.display.set_mode((width, height))
        
        tex = pygame.image.load("textures/moon2.jpg")        
        tex = tex.convert()
        self.terrain = Scenery.scenery(self,(0,0,0,0),tex)

        #pos = self.points[3]
        #self.car = Object.Object(pos[0],pos[1])

    def MainLoop(self):

        while True:
            
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == KEYDOWN:
                    if ((event.key == K_RIGHT)
                    or (event.key == K_LEFT)
                    or (event.key == K_UP)
                    or (event.key == K_DOWN)):
                        self.move(event.key,True)
                elif event.type == KEYUP:
                    if ((event.key == K_RIGHT)
                    or (event.key == K_LEFT)
                    or (event.key == K_UP)
                    or (event.key == K_DOWN)):
                        self.move(event.key,False)
            
            self.terrain.draw()
            if self.moving:
                self.terrain.move()
            
            pygame.display.update()
            
    def move(self, key, state):

        if (key == K_RIGHT):       
            self.moving = state
            
    def get_width(self):
        
        return self.width
        
    def get_height(self):
        
        return self.height
        
    def get_surface(self):
        
        return self.surface
        
if __name__=="__main__":
    
    MainWindow = PyMain(1080,720)
    MainWindow.MainLoop()